package ${package}.service.impl;

import ${package}.domain.${className};
import ${package}.repository.${className}Repository;
import ${package}.service.${className}Service;
import ${package}.service.dto.${className}Dto;
import ${package}.service.mapstruct.${className}Mapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import javax.annotation.Resource;

/**
 * @author ${author} ${date}
 */
@Service
public class ${className}ServiceImpl implements ${className}Service {

    @Resource
    private ${className}Repository ${changeClassName}Repository;
    @Resource
    private ${className}Mapper ${changeClassName}Mapper;

    @Override
    public List<${className}Dto> getAll() {
        return ${changeClassName}Mapper.toDto(${changeClassName}Repository.findAll());
    }

    @Override
    public ${className}Dto findById(Long id) {
        ${className} ${changeClassName} = ${changeClassName}Repository.findById(id).orElse(null);
        if (${changeClassName} != null) {
            return ${changeClassName}Mapper.toDto(${changeClassName});
        }
        return null;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ${className}Dto create(${className} resource) {
        return ${changeClassName}Mapper.toDto(${changeClassName}Repository.save(resource));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(${className} resource) {
        ${changeClassName}Repository.save(resource);
    }

    @Override
    public void deleteAll(List<Long> ids) {
        for (Long id : ids) {
            deleteById(id);
        }
    }

    @Override
    public void deleteById(Long id) {
        ${changeClassName}Repository.deleteById(id);
    }
}